package com.thread.book.book2;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

public class Book02 {

    public static void main(String[] args) {
        //获取java线程管理MXBean
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        //获取线程和其堆栈信息 ,参数: 是否获取同步信息(monitor,synchronized)
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.print("-----" + threadInfo.getThreadId() + " :");
            System.out.println(threadInfo.getThreadName());
        }
    }
}
